﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "GYBOM";
    Layout = "~/Views/Shared/_Genertals.cshtml";
}
@section styles{
    <style>
        .YCFile {
            display: none;
            background-color: #fff;
            width: 350px;
            height: 150px;
            position: absolute;
            left: 22%;
            top: 40%;
        }

        .YANds {
            display: flex;
            align-items: center;
            justify-content: space-between;
            background-color: #0866a563;
            border-radius: 8px;
            margin: 3px 4px;
            padding: 2px 10px;
        }

        .SHnacs {
            display: flex;
            width: 96%;
            height: 65%;
            align-items: flex-start;
            justify-content: space-between;
            background-color: #cecece;
            border-radius: 8px;
            margin: 3px 4px;
            padding: 2px 10px;
        }
    </style>
}
<div id="wid">
    <form class="row padtop col-12">
        <fieldset class="boun">
            <legend class="len">查询条件</legend>
            <div class="row">
                <p class="col">
                    @Html.Label(Resource.String152)
                    @Html.TextBox("shen")
                </p>
                <p class="col">
                    @Html.Label("物料编码")
                    @Html.TextBox("Wuliao")
                </p>
                <p class="col">
                    <input type="button" value="@Resource.String155" name="cha" class="btn-secondary btn-sm" />
                </p>
            </div>

        </fieldset>
    </form>
    <div><button id="Tiao">创建物料</button>   <button id="Chuangjian">手动创建</button></div>
    <div>
        <div id="Yin" style="display:none">
            <a href="/Material/Ecssxsdd?shu=67" id="Xiaxz" style="color: blue; border-bottom: 1px solid blue; ">@Resource.String96</a>
            <a style="color: blue; border-bottom: 1px solid blue;" id="ShangC">@Resource.String97</a>
        </div>
    </div>

    <div>
        <table class="table tab">
            <thead class="thead-light">
                <tr style="text-align-last:center;">
                    <th scope="col">@Resource.String156</th>
                    <th scope="col">@Resource.String157</th>
                    <th scope="col">发起人</th>
                    <th scope="col">状态</th>
                    <th scope="col">操作</th>
                </tr>
            </thead>
            <tbody class="gun" id="BUtain" style="height:570px;">
            </tbody>
        </table>
    </div>
    <div class="YCFile">
        <div class="YANds"><span>@Resource.String108</span><span><i class="bi bi-x-circle-fill" id="Quxiao"></i></span></div>
        <div class="SHnacs">
            <input type="file" value="" id="SHanngcF" accept="" />
            <input type="button" value="@Resource.String108" id="TIjaio" />
        </div>
    </div>
</div>
@section scripts{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>

        //点击申请单号判断当前步骤进行跳转
        $(function () {
            $("#lihfh").css({ "color": "black", "background-color": "white" })

            $("#Tiao").click(function () {
                $("#JINDN").hide()
                $("#Yin").toggle()
            })
            $("#ShangC").click(function () {
                $(".YCFile").toggle()
            })
            $("#Quxiao").click(function () {
                $(".YCFile").hide()
            })
            $(document).on("click", "#Chuangjian", function () {
                if ($("#Login_bm").text() == "设计") {
                    return
                    alert("无权限")
                }
                window.location.href = "/Cuobaojia/Application";
            })
            $(document).on("click", "#Shancu", function (e) {
                var id = $(e.target).parent().parent().children().eq(1).text()
                if (confirm("是否删除该条！")) {
                    $.ajax({
                        url: '/Home/GYBOM',
                        type: 'POST',
                        data: { "id": id, "states": 2 },
                        success: function (date) {
                            alert(date)
                            skonf()
                        },
                        error: function () {
                            alert("错误 请重试！")
                        }
                    })
                }
            })

            $(document).on("click", "#Dan", function (e) {
                var bian = $(e.target).text()
                var bei = $(this).parent().children().eq(5).text()
                var id = $(this).parent().children().eq(1).text()
                var Buz = $(this).parent().children().eq(7).text()
                console.log(bei)
                if (bei == "保存") {
                    window.location.href = "/Cuobaojia/Application?id=" + id;
                } else {
                    if (Buz == 2) {
                        window.location.href = "/Cuobaojia/Boms?names=" + bian;
                    } else {
                        window.location.href = "/Material/ERPGongy?names=" + bian;
                    }
                }
            })
            $("#TIjaio").click(function () {
                var name = $("#Login_N").text()
                var fileUpload = $('#SHanngcF')[0];
                if ($("#Login_bm").text() == "设计") {
                    return
                    alert("无权限")
                }
                if (fileUpload.files.length > 0) {
                    var formData = new FormData();
                    formData.append('file', fileUpload.files[0]);
                    $.ajax({
                        url: '/Home/ExcelFilePath',
                        type: 'POST',
                        data: formData,
                        processData: false,		//用于对data参数进行序列化处理 这里必须false
                        contentType: false,
                        success: function (fgggh) {
                            console.log(fgggh)
                            if (fgggh == "料号为空") {
                                alert("料号为空")
                            }
                            else {
                                $.ajax({
                                    url: '/Home/cghangapk',
                                    type: 'POST',
                                    data: { "fgggh": fgggh, "name": name },
                                    success: function (date) {
                                        if (date == "1") {
                                            alert("创建成功")
                                            skonf()
                                        }
                                    },
                                    error: function () {
                                        alert("错误 请重试！")
                                    }
                                })
                            }
                        },
                        error: function (xhr) {
                            alert("系统错误" + xhr);
                        }
                    })
                } else {
                    alert('请选择要上传的文件！');
                }
            })
        })
        //查询功能
        $(function () {
            $('input[name="cha"]').click(function () {
                skonf()
            })
            skonf()
        })
        function skonf() {
            var shen = $("#shen").val()
            var App_Kehu = $("#Wuliao").val()
            $.ajax({
                url: '/Home/GYBOM',
                type: 'POST',
                data: { "AP_bian": shen, "App_Kehu": App_Kehu, "states": 1 },
                success: function (date) {
                    console.log(date)
                    createRow(date);
                },
                error: function () {
                    alert("错误 请重试！")
                }
            })
        }
        function createRow(date) {
            $("#BUtain tr").remove();
            var ddjjfj = 1
            var ZJ = $("#Login_zj").text()*1
            var MC = $("#Login_N").text()
            var BM = $("#Login_bm").text()
            $.each(date, function (i, item) {
                var $tr =
                    (`
                <tr>
                    <td>${ddjjfj}</td>
                    <td style="display:none">${item.App_id}</td>
                    <td id="Dan" style="color:#2a6bcc;">${item.AP_bian}</td>
                    <td class="sr-only C_jin" style="display:none" id="poi">${item.App_bu}</td>
                    <td>${item.AP_ren}</td>
                    <td>${item.App_bei}</td>
                    <td><button id="Shancu" style="border:0;color:red;background:none">删除</button></td>
                    <td style="display:none">${item.App_bu}</td>
                </tr>
                `);
               
                if (MC == item.AP_ren || (ZJ >= 2 && ddjjfj < 100 && BM!="设计")) {
                    $("#BUtain").append($tr);
                    ddjjfj++
                }
            })
        }
    </script>
}